
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
    <title>南湖量化</title>
    <link rel="stylesheet" href="//static.360buyimg.com/finance/base/1.2.0/css/base.css"/>
    <link rel="stylesheet" href="//static.360buyimg.com/finance/platform/quantification/1.0.0/css/index.css"/>
    <link rel="stylesheet" href="//static.360buyimg.com/finance/platform/quantification/1.0.0/css/edit.css"/>
    <link rel="stylesheet" href="/static/UPQuant/css/reset.css">
	<link rel="stylesheet" href="/static/UPQuant/css/index.css">
    <link rel="stylesheet" href="/static/UPQuant/js/datapicker/css/pikaday.css">
    <style type="text/css" media="screen">
        #sourceCode {
            position: absolute;
            height: 770px;
            width: 100%;
            margin: 0 0 0 0;
        }
         .status-bar {
        position: absolute;
        bottom: 4px;
        right: 24px;
        z-index: 100;
        height: 30px;
        line-height: 30px;
        border-radius: 15px;
        text-align: center;
        color: #72cbf9;
        width: 270px;
        cursor: move;
        font-size: 10px;
        transition: width 0.2s, height 0.2s, color 0.2s;
        background: rgba(102, 153, 255, 0.25);
        overflow: hidden;
    }

    .status-bar-active {
        color: #9f6;
        background: rgba(153, 204, 102, 0.25);
    }
    </style>
</head>

<script src="/static/UPQuant/js/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/UPQuant/js/ace/ext-language_tools.js"></script>
<script src="/static/UPQuant/js/datapicker/moment.js"></script>
<script src="/static/UPQuant/js/datapicker/pikaday.js"></script>

<script>
    function submitContext() {
        var temp = document.createElement("form");
        temp.method = "post";
        temp.style.display = "none";

        var editor = ace.edit("sourceCode");
        var editSession = editor.getSession();
        var editDocument = editSession.getDocument();


        var arrayCode = editDocument.getAllLines();
        var numNode = document.createElement("input");
        numNode.name = 'lines';
        numNode.value = arrayCode.length;
        temp.appendChild(numNode);
        console.log(numNode.value);

        for (var lineCode in arrayCode)
        {
            var opt = document.createElement("input");
            opt.name = "pythonCode_" + lineCode.toString();
            opt.value = arrayCode[lineCode];
            temp.appendChild(opt);
        }
        document.body.appendChild(temp);
        temp.submit();
        return false;
    }

    function backTest(){
        var temp = document.createElement("form");
        temp.method = "post";
        temp.style.display = "none";

        var editor = ace.edit("sourceCode");
        var editSession = editor.getSession();
        var editDocument = editSession.getDocument();
        var arrayCode = editDocument.getAllLines();


        var numNode = document.createElement("input");
        numNode.name = 'execlines';
        numNode.value = arrayCode.length;
        temp.appendChild(numNode);

        for (var lineCode in arrayCode)
        {
            var opt = document.createElement("input");
            opt.name = "pythonCode_" + lineCode.toString();
            opt.value = arrayCode[lineCode];
            temp.appendChild(opt);
        }

        var picker1 = new Pikaday({ field: document.getElementById('datepicker_begin') });
        var picker1_document = document.createElement("input");
        picker1_document.name = "start_date";
        picker1_document.value = picker1.toString("YYYY-MM-DD");
        temp.appendChild(picker1_document);


        var picker2 = new Pikaday({ field: document.getElementById('datepicker_end') });
        var picker2_document = document.createElement("input");
        picker2_document.name = "end_date";
        picker2_document.value = picker2.toString("YYYY-MM-DD");
        temp.appendChild(picker2_document);

        var cash = document.getElementById("principal").value;
        var cash_document = document.createElement("input");
        cash_document.name = "cash";
        cash_document.value = cash;
        temp.appendChild(cash_document);
        //console.log(cash);

        document.body.appendChild(temp);
        temp.submit();
        return temp;
    }
</script>

<body>
<div class="header">
    <div class="header_main">
        <img src="/static/UPQuant/images/logo.png"  class="logo">
        <div class="nav">
            <ul>
                <li><a href="#">首页</a></li>
                <li><a href="#">云数据</a></li>
                <li class="on"><a href="#">云策略</a></li>
                <li><a href="#">云交易</a></li>
                <li><a href="#">云资管</a></li>
            </ul>
        </div>
    </div>
</div>
<div class="eidit-container">
    <div class="eidit-con-title clearfix">
        <div class="eidit-main">
            <ul class="result-list clearfix">
                <li class="add-li-col">
                    <a href="#" class="state">编辑策略</a>
                </li>
                <li>
                    <a href="#" class="state">回测结果</a>
                </li>
                <li>
                    <a href="#" class="state state-end">回测历史</a>
                </li>
            </ul>
        </div>
        <div class="new-eidit clearfix">
            <a href="" class="left-return"></a>
            <input type="text" id="strategyName" maxlength="35" class="eidit-text" value="新建策略2016-08-22 19:57:10"/>
        </div>
    </div>
    <div class="edit-container clearfix">
        <div id="j_leftCon" class="edit-container-leftbar">
            <div class="edit-left-con clearfix">
                <div class="error-tishi" id="editMessage" style="display: none"></div>
                <div class="write-eidit">
                    <a href="javascript:void(0);" onclick="submitContext()" class="bianyi">编译</a>
                </div>
            </div>
            <div id="sourceCode"></div>
            <div id="j_sidebar" class="edit-left-sidebar"></div>
            <div class="state-wrap4" style="display: none">
                <div class="state4"></div>
                <div class="state4-close"></div>
            </div>
        </div>
        <div class="edit-container-rightbar">
            <div class="edit-right-con clearfix">
                <div class="edi-wraps">
                    <input id="datepicker_begin" name="startDate" class="date" readOnly="readOnly"
                           type="text" value="2015-01-01"/>
                    <span class="text">至</span>
                    <input id="datepicker_end" name="endDate" readOnly="readOnly" class="zhi-dates" type="text"
                           value="2016-01-01"/>
                    <div class="dollar">
                    <span class="do-icon">￥</span>
                    <input name="principal" id="principal" type="number" step="1000" class="jine" value="1000000"
                           maxlength="6"/>
                    </div>
                    <a href="javascript:void(0);" onclick="backTest()" class="renturn-back">运行回测</a>
                </div>
            </div>
            <div class="bianji-con"></div>
            <div class="journal"></div>
            <div class="state-wrap5">
                <div class="state5"></div>
                <div class="state5-close"></div>
            </div>
            <div class="state-wrap6">
                <div class="state6"></div>
                <div class="state6-close"></div>
            </div>
        </div>
    </div>
</div>
<script>
    ace.require("ace/ext/language_tools");
    var editor = ace.edit("sourceCode");
    editor.setOptions({
    enableBasicAutocompletion: true,
    enableSnippets: true,
    enableLiveAutocompletion: true
    });
    editor.setFontSize(18);
    editor.setTheme("ace/theme/eclipse");
    editor.getSession().setMode("ace/mode/python");
    //var codeSource = ;
    //console.log('-----' + codeSource);
    editor.setValue({{ results|safe }});

    var picker1 = new Pikaday({field: document.getElementById('datepicker_begin') });
    picker1.setDate({{ begin_date|safe }});
    var picker2 = new Pikaday({ field: document.getElementById('datepicker_end') });
    picker2.setDate({{ end_date|safe }});
    document.getElementById("principal").setAttribute('value', {{ cash|safe }});
</script>
</body>
</html>